<template>
  <div class="app-container">
    <el-row :gutter="20">
        <!--题库数据-->
        <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="repoName"
            placeholder="请输入题库名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="repoOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <!--试题数据-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="标题" prop="title">
            <el-input
              v-model="queryParams.title"
              placeholder="标题"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="题型" prop="questionType">
            <el-select  v-model="queryParams.questionType" placeholder="请选择题型" clearable>
              <el-option
                v-for="dict in dict.type.question_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['paper:question:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['paper:question:edit']"
            >编辑</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['paper:question:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              plain
              icon="el-icon-upload2"
              size="mini"
              @click="handleImport"
              v-hasPermi="['paper:question:export']"
            >导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-popover
              ref="popover"
              placement="bottom"
              trigger="hover">
              <div style="text-align: right; margin: 0">
                <el-button type="warning" plain size="mini"  @click="handleExportFile('1','xlsx')">导出excel</el-button>
                <el-button type="warning" plain size="mini" @click="handleExportFile('2','docx')">导出word</el-button>
                <el-button type="warning" plain size="mini" @click="handleExportFile('3','pdf')">导出pdf</el-button>
              </div>
            </el-popover>
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              v-hasPermi="['paper:question:export']"
              v-popover:popover
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="questionList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="编号" align="center" prop="id" />
          <el-table-column label="标题" align="center" prop="title" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column label="最新版本号" align="center" prop="versionNo" />
          <el-table-column label="所属机构" align="center" prop="deptName" />
          <el-table-column label="题型" align="center" prop="questionTypeName" />
          <el-table-column label="题库" align="center" prop="repoName" />
          <el-table-column label="章节" align="center" prop="sectionName" />
          <el-table-column label="难度" align="center" prop="level">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.question_level" :value="scope.row.level"/>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="createTime" width="200">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['paper:question:edit']"
              >编辑</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['paper:question:remove']" >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!-- 添加或编辑试题对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="题库" prop="sectionId" required>
              <treeselect v-model="form.sectionId" :options="repoOptionsSelect" :normalizer="normalizer"  placeholder="请选择题库" />
            </el-form-item>
         </el-col>
         <el-col :span="12">
            <el-form-item label="题型" prop="questionType" required>
            <el-select v-model="form.questionType" placeholder="请选择题型" @change="questionTypeChange">
              <el-option
                v-for="dict in dict.type.question_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="标题" prop="title" required>
              <el-input v-model="form.title" placeholder="请输入标题">
                 <el-button slot="append" icon="el-icon-edit" @click="showEditor(form,'title')"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.questionType==0||form.questionType==1||form.questionType==11">
          <el-col :span="24">
            <el-form-item label="选项" required>
              <el-form-item :label="option.seqCode" :key="option.seqCode"  v-for="(option,index) in form.options"  label-width="50px" class="question-option-label">
                <el-input v-model="option.seqCode"  style="width:50px;" />
                <el-input v-model="option.content" class="question-option-content-input">
                  <el-button slot="append" icon="el-icon-edit" @click="showEditor(option,'content')"></el-button>
                </el-input>
                <el-checkbox v-model="option.answerFlag" @change="forceUpdate"></el-checkbox>
                <el-button type="danger" size="mini" icon="el-icon-delete"  @click="questionOptionRemove(index)" class="question-option-remove"/>
              </el-form-item>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.questionType>=2&&form.questionType<=6">
          <el-col :span="24">
            <el-form-item label="答案" required>
              <el-form-item :label="answer.seqCode" :key="answer.seqCode"  v-for="(answer,index) in form.answers"  label-width="50px" class="question-option-label">
                <!-- <el-input v-model="option.seqCode"  style="width:50px;" /> -->
                <el-input v-model="answer.answer" class="question-option-content-input">
                  <el-button slot="append" icon="el-icon-edit" @click="showEditor(answer,'answer')"></el-button>
                </el-input>
                <el-button type="danger" size="mini" icon="el-icon-delete"  @click="questionOptionRemove(index)" class="question-option-remove"/>
              </el-form-item>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.questionType==7">
          <el-col :span="24">
            <el-form-item label="选项" required>
              <el-form-item :label="option.seqCode" :key="option.seqCode"  v-for="(option,index) in form.options"  label-width="50px" class="question-option-label">
                <el-input v-model="option.seqCode"  style="width:50px;" />
                <el-input v-model="option.content" class="question-option-content-input">
                  <el-button slot="append" icon="el-icon-edit" @click="showEditor(option,'content')"></el-button>
                </el-input>
                <el-button type="danger" size="mini" icon="el-icon-delete"  @click="questionOptionRemove(index)" class="question-option-remove"/>
              </el-form-item>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.questionType==7">
          <el-col :span="24">
            <el-form-item label="标题" required> 
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="questionB1Add">新增</el-button>
            </el-form-item></el-col>
          <el-col :span="24"  :key="index"  v-for="(choice,index) in form.choices">
              <el-form-item :label="(index+1)+'.'" :key="index"  label-width="50px" class="question-option-label">
                <el-input v-model="choice.title" class="question-option-content-input">
                  <el-button slot="append" icon="el-icon-edit" @click="showEditor(choice,'title')"></el-button>
                </el-input>
                <el-button type="danger" size="mini" icon="el-icon-delete" class="question-option-remove"  @click="questionB1Remove(index)"/>
                <el-form-item label="答案">
                  <el-radio-group v-model="choice.answer" @change="forceUpdate">
                    <el-radio v-for="option in form.options" :key="option.seqCode" :label="option.seqCode">{{option.seqCode}}</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="解析">
                  <el-input v-model="choice.explain" placeholder="请输入解析">
                  <el-button slot="append" icon="el-icon-edit" @click="showEditor(choice,'explain')"></el-button>
                </el-input>
                </el-form-item>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.questionType==8||form.questionType==9">
          <el-col :span="24">
            <el-form-item label="标题"> 
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="questionA3A4Add">新增</el-button>
            </el-form-item></el-col>
          <el-col :span="24"  :key="index"  v-for="(question,index) in form.questions">
              <el-form-item :label="(index+1)+'.'" :key="index"  label-width="50px" class="question-option-label">
                <el-input v-model="question.title" class="question-option-content-input">
                  <el-button slot="append" icon="el-icon-edit" @click="showEditor(question,'title')"></el-button>
                </el-input>
                <!-- <el-button type="danger" size="mini" icon="el-icon-delete" class="question-option-remove"  @click="questionA3A4Remove(index)"/> -->
                <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="questionA3A4Remove(index)">删除小题</el-button>
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="questionA3A4OptionAdd(question.options)">添加选项</el-button>
                <el-form-item label="选项" required>
                  <el-form-item :label="option.seqCode" :key="option.seqCode"  v-for="(option,indexOption) in question.options"  label-width="50px" class="question-option-label">
                    <el-input v-model="option.seqCode"  style="width:50px;" />
                    <el-input v-model="option.content" class="question-option-content-input">
                  <el-button slot="append" icon="el-icon-edit" @click="showEditor(option,'content')"></el-button>
                </el-input>
                    <el-checkbox v-model="option.answerFlag" @change="forceUpdate"></el-checkbox>
                    <el-button type="danger" size="mini" icon="el-icon-delete"  @click="questionA3A4OptionRemove(question.options,indexOption)" class="question-option-remove"/>
                  </el-form-item>
                </el-form-item>
                <el-form-item label="解析">
                  <el-input v-model="question.explain" placeholder="请输入解析" />
                </el-form-item>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.questionType==10">
          <el-col :span="24">
            <el-form-item label="答案">
              <el-radio-group v-model="form.answerFlag" @change="forceUpdate">
                <el-radio label="1">是</el-radio>
                <el-radio label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.questionType!=7&&form.questionType!=8&&form.questionType!=9">
          <el-col :span="24">
            <el-form-item label="解析" prop="explain">
              <el-input v-model="form.explain" placeholder="请输入解析">
                <el-button slot="append" icon="el-icon-edit" @click="showEditor(form,'explain')"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="难度：" required>
              <el-rate v-model="form.level" :max="3" class="question-level-rate"></el-rate>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
        <el-button type="success" @click="questionOptionAdd" v-if="form.questionType!=8&&form.questionType!=9">添加选项</el-button>
      </div>
    </el-dialog>

    <!-- 添加或编辑富媒体对话框 -->
    <el-dialog  :visible.sync="openEditor" width="800px" append-to-body>
      <editor  v-model="editorValue" :min-height="192"/>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEditor">确 定</el-button>
        <el-button @click="cancelEditor">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户试题对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="导入结果"
      :visible.sync="importDialogVisible"
      width="40%">
      <span v-html="importResult"></span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="importDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listQuestion, getQuestion, delQuestion, editChoice, editAnswer,editB1,editA3A4,editTF,repoTreeSelect,importMonitor,exportQuestion } from "@/api/paper/question";
import { listRepo } from "@/api/paper/repo";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Question",
  dicts: ['question_type','question_level'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 试题表格数据
      questionList: [],
      // 弹出层标题
      title: "",
      // 题库树选项
      repoOptions: undefined,
      // 题库树选择列表
      repoOptionsSelect:[],
      // 题库名称
      repoName:undefined,
      // 是否显示弹出层
      open: false,
      //是否显示富文本框
      openEditor: false,
      editorObject: null,
      editorValue: null,
      param: '',
      defaultProps: {
        children: "children",
        label: "label"
      },
      importDialogVisible: false,
      importResult: '',
      timerId: null,
      options: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        versionNo: null,
        questionType: null,
        repoId: null,
        sectionId: null,
        level: null,
      },
      // 表单参数
      form: {},
      // 试题导入参数
      upload: {
        // 是否显示弹出层（试题导入）
        open: false,
        // 弹出层标题（试题导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/paper/question/importQuestion"
      },
      // 表单校验
      rules: {
        sectionId: [
          { required: true, message: "题库不能为空", trigger: "blur" }
        ],
        questionType: [
          { required: true, message: "题型不能为空", trigger: "blur" }
        ],
        title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        level: [
          { required: true, message: "难度不能为空", trigger: "blur" }
        ],
      }
    };
  },
  watch: {
    // 根据名称筛选题库树
    repoName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
    this.getRepoTree();
  },
  methods: {
    /** 查询试题列表 */
    getList() {
      this.loading = true;
      listQuestion(this.queryParams).then(response => {
        this.questionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     /** 转换试题题库章节数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.repoId,
        label: node.repoName,
        children: node.children
      };
    },
     /** 查询题库下拉树结构 */
     getRepoTree() {
      repoTreeSelect().then(response => {
        this.repoOptions = response.data;
      });
    },
    /** 查询题库下拉树结构 */
    getTreeselect() {
      listRepo().then(response => {
        this.repoOptionsSelect = this.handleTree(response.data, "repoId");
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.sectionId = data.id;
      this.handleQuery();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        questionType: null,
        sectionId: null,
        options: [
          { seqCode: 'A', content: '', answerFlag: false },
          { seqCode: 'B', content: '', answerFlag: false },
          { seqCode: 'C', content: '', answerFlag: false },
          { seqCode: 'D', content: '', answerFlag: false },
          { seqCode: 'F', content: '', answerFlag: false }
        ],
        answers: [],
        choices: [],
        questions: [],
        answerFlag: "",
        title: "",
        explain: "",
        level: 1
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getTreeselect();
      this.open = true;
      this.title = "添加试题";
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      const id = row.id || this.ids
      getQuestion(id).then(response => {
        this.form = response.data;
        if(row.questionType=="0"||row.questionType=="1"||row.questionType=="11"){
          this.form.options.forEach(item=>{
              //  item.checked=item.answerFlag=="1"
              })
        }
        if(row.questionType=="8"||row.questionType=="9"){
          this.form.questions.forEach(qustion=>{
              qustion.options.forEach(option=>{
               // option.checked=option.answerFlag=="1"
              })
          })
        }
        if(row.questionType=="10"){
          this.form.answerFlag=this.form.answerFlag+""
        }
        this.open = true;
        this.title = "编辑试题";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.form.questionType=="0"||this.form.questionType=="1"||this.form.questionType=="11"){
            this.form.options.forEach(item=>{
                  //item.answerFlag=item.checked?"1":"0";
              })
            if (this.form.id != null) {
              editChoice(this.form).then(response => {
                this.$modal.msgSuccess("编辑成功");
                this.open = false;
                this.getList();
              });
            } else {
              editChoice(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
          if(this.form.questionType>="2"&&this.form.questionType<="6"){
              this.form.answers.forEach((item,i)=>{
                  item.seqCode=i+1+"";
              })
              editAnswer(this.form).then(response => {
                if (this.form.id != null){
                  this.$modal.msgSuccess("编辑成功");
                }else{
                  this.$modal.msgSuccess("新增成功");
                }
                this.open = false;
                this.getList();
              });
          }
          if(this.form.questionType=="7"){
              this.form.options.forEach(item=>{
                //  item.answerFlag=item.checked?"1":"0";
              })
              editB1(this.form).then(response => {
                if (this.form.id != null){
                  this.$modal.msgSuccess("编辑成功");
                }else{
                  this.$modal.msgSuccess("新增成功");
                }
                this.open = false;
                this.getList();
              });
          }
          if(this.form.questionType=="8"||this.form.questionType=="9"){
              this.form.questions.forEach(qustion=>{
                  qustion.options.forEach(option=>{
                    //option.answerFlag=option.checked?"1":"0";
                  })
              })
              editA3A4(this.form).then(response => {
                if (this.form.id != null){
                  this.$modal.msgSuccess("编辑成功");
                }else{
                  this.$modal.msgSuccess("新增成功");
                }
                this.open = false;
                this.getList();
              });
          }
          if(this.form.questionType=="10"){
            if (this.form.id != null) {
              editTF(this.form).then(response => {
                this.$modal.msgSuccess("编辑成功");
                this.open = false;
                this.getList();
              });
            } else {
              editTF(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }      
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除试题编号为"' + ids + '"的数据项？').then(function() {
        return delQuestion(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 type:1-excel,2-word,3-pdf */
    handleExportFile(type,suffix) {
      if(this.multiple){
        this.$modal.msgError('未勾选需要下载的试题！')
      }else{
        const ids = this.ids;
        this.download('/paper/question/exportQuestion/'+type+'/'+ids, {
          ...this.queryParams
        }, `question_${new Date().getTime()}.`+suffix)
      }
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "试题导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      let a = document.createElement('a');
      a.href = `/static/questionTemplate.xlsx`;
      a.download = '试题导入模板.xlsx';
      a.click();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.importDialogVisible = true;
      this.importResult = "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>试题导入中...</div>";
      const that = this;
      this.timerId = setTimeout(function () {
          that.importMonitorResult(response.msg)
        }, 1000);
    },
    importMonitorResult(uuid){
      importMonitor(uuid).then(response => {
        this.importResult = "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.data.result + "</div>";
        this.getList();
        if(response.data.status=="1"){
          clearInterval(this.timerId)
        }
      });
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    questionOptionRemove(index) {
      if(this.form.questionType=="0"||this.form.questionType=="1"||this.form.questionType=="7"||this.form.questionType=="11"){
        this.form.options.splice(index, 1)
      }
      if(this.form.questionType=="2"){
        this.form.answers.splice(index, 1)
      }
    },
    questionA3A4OptionRemove(options,index) {
      options.splice(index,1)
    },
    questionB1Remove(index){
      this.form.choices.splice(index, 1)
    },
    questionA3A4Remove(index){
      this.form.questions.splice(index, 1)
    },
    forceUpdate() {
      this.$forceUpdate();
    },
    questionOptionAdd() {
      if(this.form.questionType=="0"||this.form.questionType=="1"||this.form.questionType=="7"||this.form.questionType=="11"){
        let options = this.form.options
        let nexSeqCode = "A"
        if (options!=null&&options.length > 0) {
          let last = options[options.length - 1]
          nexSeqCode = String.fromCharCode(last.seqCode.charCodeAt() + 1)
        } else{
          options = []
        }
        options.push({ seqCode: nexSeqCode, content: '',checked: false,answerFlag: '0' })
      }
      if(this.form.questionType>="2"&&this.form.questionType<="6"){
        let answers = this.form.answers
        let nexSeqCode = '1'
        if (answers!=null&&answers.length > 0) {
          let last = answers[answers.length - 1]
          nexSeqCode = String.fromCharCode(last.seqCode.charCodeAt() + 1)
        } else {
          answers = []
        }
        answers.push({ seqCode: nexSeqCode,  answer: '1'})
      }
    },
    questionA3A4OptionAdd(options) {
        let nexSeqCode = "A"
        if (options!=null&&options.length > 0) {
          let last = options[options.length - 1]
          nexSeqCode = String.fromCharCode(last.seqCode.charCodeAt() + 1)
        } else{
          options = []
        }
        options.push({ seqCode: nexSeqCode, content: '',checked: false,answerFlag: false })
    },
    questionB1Add () {
        let choices = this.form.choices
        choices.push({ title: '', explain: '',subOption:{ seqCode: ""} })
    },
    questionA3A4Add () {
        let questions = this.form.questions
        questions.push({ title: '', explain: '',
        options:[
          { seqCode: 'A', content: '', answerFlag: false },
          { seqCode: 'B', content: '', answerFlag: false },
          { seqCode: 'C', content: '', answerFlag: false },
          { seqCode: 'D', content: '', answerFlag: false },
          { seqCode: 'F', content: '', answerFlag: false }
         ] })
    },
    questionTypeChange(value){
      if(value>="2"&&value<="6") {
        this.form.answers=[{ seqCode: '1', answer: '' }]
      }else if(value=="7"){
        this.form.choices=[{ title: '', explain: '',subOption:{ seqCode: ""} }]
      }else if(value=="8"||value=="9"){
        this.form.questions=[{ title: '', explain: '',
        options:[
          { seqCode: 'A', content: '', answerFlag: false },
          { seqCode: 'B', content: '', answerFlag: false },
          { seqCode: 'C', content: '', answerFlag: false },
          { seqCode: 'D', content: '', answerFlag: false },
          { seqCode: 'F', content: '', answerFlag: false }
         ] }]
      }
    },
    showEditor(object,param){
      this.editorObject = object;
      this.editorValue = this.editorObject[param];
      this.param = param;
      this.openEditor = true;
    },
    cancelEditor(){
      this.openEditor = false;
    },
    submitEditor(){
      this.openEditor = false;
      this.editorObject[this.param] = this.editorValue
    }
  }
};
</script>
